<?php
namespace app\index\model;

use app\common\model\WebComm;
use app\common\model\AssortComm;


class Index
{

    ///获取首页数据
    public function getIndexData(){
        ///使用到的model
        $assortComm = new AssortComm();
        $webComm = new WebComm();

        ///获取分类list
        $class_data_arr = $assortComm->getValidAssort();

        ///分类随机显示条数
        $subscript_arr  = array(12,15,10,7);
        $subscript_count  = 4;

        ///获取分类下网站数据list
        $index_data_arr = array();
        foreach($class_data_arr as $key=>$value){
            if(empty($key)||empty($value)||is_array($value)){continue;}
            $son_count = $webComm->getAssortWebCount($key);
            if($son_count < 1){continue;}
            $son = $webComm->getAssortWebLimitData($key,$subscript_arr[$key%$subscript_count] ?? 7);
            $index_data_arr[] = array('assort_id'=>$key,'father'=>$value,'son_count'=>$son_count,'son'=>$son);
            unset($son);
        }
        unset($class_data_arr);

        return $index_data_arr;
    }


    ///获取制定分类数据
    public function getDesClassData($c_id = 0){
        $webComm = new WebComm();
        return $webComm->getDesAssortWebAllData($c_id);
    }


    ///获取详情数据
    public function getWebDetails($w_id =0){
        $webComm = new WebComm();
        return $webComm->getWebDataDetail($w_id);
    }


}